﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace SLGameEngine
{
    public class ObjectMgr
    {
        public static List<ObjectMap> MapObjects = new List<ObjectMap>();
        public static List<ObjectGame> GameObjects = new List<ObjectGame>();
        public static List<ObjectCreature> CreatureObjects = new List<ObjectCreature>();

        public static List<ObjectBase> ObjectBaseTemplates = new List<ObjectBase>();
        public static Dictionary<int, ObjectBase> ObjectTemplateDictionary = new Dictionary<int, ObjectBase>();

        public static void InitializeObjectTemplates(List<ObjectBase> templates)
        {
            foreach (ObjectBase obj in templates)
            {
                ObjectBaseTemplates.Add(obj);
                ObjectTemplateDictionary.Add(obj.BaseObjectID, obj);
            }
        }

        public static ObjectBase GetBaseObject(int ID)
        {
            if (ObjectTemplateDictionary.ContainsKey(ID))
                return ObjectTemplateDictionary[ID];

            return null;
        }

        public static ObjectBase GetCreatureObjectsCollision(Point pt, ref Point selectionPoint)
        {
            for (int i = 0; i < ObjectMgr.CreatureObjects.Count; i++)
            {
                if (true == ObjectMgr.CreatureObjects[i].DetectCollision(pt, ref selectionPoint))
                    return ObjectMgr.CreatureObjects[i];
            }

            return null;
        }

        public static ObjectBase GetGameObjectsCollision(Point pt, ref Point selectionPoint)
        {
            for (int i = 0; i < ObjectMgr.GameObjects.Count; i++)
            {
                if (true == ObjectMgr.GameObjects[i].DetectCollision(pt, ref selectionPoint))
                    return ObjectMgr.GameObjects[i];
            }

            return null;
        }
        public static ObjectBase GetMapObjectsCollision(Point pt, ref Point selectionPoint)
        {
            for (int i = 0; i < ObjectMgr.MapObjects.Count; i++)
            {
                if (true == ObjectMgr.MapObjects[i].DetectCollision(pt, ref selectionPoint))
                    return ObjectMgr.MapObjects[i];
            }

            return null;
        }
    }
}
